package com.kingsoft.miot.bridge.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.kingsoft.miot.bridge.config.RedisConfig;
import com.kingsoft.miot.bridge.controller.tmp.UUser;
import com.kingsoft.miot.bridge.service.impl.manager.ManagerServiceImpl;
import com.kingsoft.miot.bridge.service.manager.ManagerService;
import com.kingsoft.miot.bridge.utils.RedisUtil;

@RestController /* 如果无这个注解回报 could not resolve path 异常 */
public class TestController {

	@Autowired
	private RedisUtil redisUtils;
	
	@Autowired
	private ManagerService managerService;

	@RequestMapping(value = "/dd/of/{id}", method = RequestMethod.POST)
	public void test(@RequestBody UUser user, @PathVariable String id) {
		System.out.println(user);
		System.out.println(id);
	}

	/**
	 * 
	 * @param user
	 */
	@RequestMapping(value = "/test/controller", method = RequestMethod.POST)
	public void test1(@RequestBody UUser user) {
		System.out.println("进入test controller");
//		System.out.println(redisTest("melody"));
		
		System.out.println(user);
	}

	@RequestMapping(value = "/testaa/redis", method = RequestMethod.POST)
	public void testAdd() {
		System.out.println("进入add controller");
//		System.out.println(addTest("melody"));
		String addTest = managerService.addTest("melody");
		System.out.println(addTest);
	}

	@RequestMapping(value = "/testgg/redis", method = RequestMethod.POST)
	public void testGet() {
		System.out.println("进入get controller");
		String test = managerService.getTest("melody");
		System.out.println(test);
	}

//	@Cacheable(value = RedisConfig.HOTEL_CACHE + "12h", key = "#id")
	public String getTest(String id) {
//		Object leftPop = redis.opsForList().
//		if(leftPop == null) {
//		Object data = redisUtils.hget(RedisConfig.MANAGER_CACHE, "melody");
//		if (data != null) {
//			return data.toString();
//		}
		
		return new String(id + new Date().getTime());
//		}
//		return new String(leftPop.toString());
//		return leftPop.toString();
	}

//	@CachePut(value = RedisConfig.HOTEL_CACHE + "12h", key = "#id")
	public String addTest(String id) {
		String x = id + new Date().getTime();
//		boolean isSuccess = redisUtils.hset(RedisConfig.MANAGER_CACHE, "melody", x, 100);
//		redis.opsForList().leftPush(id,x );
		return x;
	}

}
